package l1j.opqlo.Timer.血量魔量恢復;

import java.util.Collection;
import java.util.TimerTask;
import java.util.concurrent.ScheduledFuture;

import l1j.opqlo.Server.L1World.WorldElf;
import l1j.server.Thread.PcOtherThreadPool;
import l1j.server.server.model.Instance.L1PcInstance;

/**
 * PC HP回復時間軸(精靈)
 *
 * @author dexc
 *
 */
public class 血量恢復妖精 extends TimerTask {

	// private static final Log _log = LogFactory.getLog(HprTimerElf.class);

	private ScheduledFuture<?> _timer;

	@Override
	public void run() {
		try {
			final Collection<L1PcInstance> allPc = WorldElf.get().all();
			// 不包含元素
			if (allPc.isEmpty()) {
				return;
			}

			for (final L1PcInstance tgpc : allPc) {
				final 血量恢復控制 hpr = 血量恢復控制.get();
				if (hpr.check(tgpc)) {
					hpr.checkRegenHp(tgpc);
					Thread.sleep(1);
				}
			}

			/*
			 * for (final L1PcInstance tgpc : allPc) { final HprExecutor hpr =
			 * HprExecutor.get(); if (hpr.check(tgpc)) { hpr.checkRegenHp(tgpc);
			 * Thread.sleep(1); } }
			 */

		} catch (final Exception e) {
			// _log.error("Pc(精靈) HP自然回復時間軸異常重啟", e);
			PcOtherThreadPool.get().cancel(this._timer, false);
			final 血量恢復妖精 hprElf = new 血量恢復妖精();
			hprElf.start();
		}
	}

	public void start() {
		final int timeMillis = 1000;// 1秒
		this._timer = PcOtherThreadPool.get().scheduleAtFixedRate(this,
				timeMillis, timeMillis);
	}
}
